//=============================================================================
// Generator.
//=============================================================================

class TFGenerator extends TFStation
	placeable;

function TakeDamage(int Damage, Pawn instigatedBy, Vector hitlocation, Vector momentum, class<DamageType> damageType)
{
	if ( Role < ROLE_Authority ) return;

    if(grade==3) damage*=5;

	super.takedamage(damage,instigatedBy,hitlocation,momentum,damageType);
}

state Ready
{
    function BeginState()
    {
        super.BeginState();

        //tfgri(level.Game.GameReplicationInfo).maxres[myteam]+=50;

        if(myteam==0) setstaticmesh(StaticMesh'TFMedia.Buildings.tfGeneratorRed');
        else setstaticmesh(StaticMesh'TFMedia.Buildings.tfGeneratorBlu');

        settimer(1,true);
    }

    function Timer()
    {
        local actor a;
        local float rate, factor/*, tmp, amount, amount2*/;
        local tfgeneratorfx gfx;

        //factor=tfgri(level.Game.GameReplicationInfo).getTechFactor(myteam, 2);
        if(nearOutpost>1) factor=2;
        else factor=1;

        rate=float(tfgame(level.game).GeneratorRate)/60;

        if(grade==3)
        {
            soundvolume=196;
            soundpitch=48;
            spawn(class'Taskforces.tfgenOverfx');
            tfgri(level.Game.GameReplicationInfo).AddTeamRes((rate*3), myteam, false);
        }
        else if(grade==2) tfgri(level.Game.GameReplicationInfo).AddTeamRes((rate*1.5)*factor, myteam, false);
        else tfgri(level.Game.GameReplicationInfo).AddTeamRes(rate*factor, myteam, false);

        if(grade>=2)
        {
            foreach CollidingActors(class'actor',a,520,location)
            {
                if(grade>1 && tfMinerals(a)!=none)
                {
                    tfgri(level.Game.GameReplicationInfo).AddTeamRes((rate*3)*factor, myteam, false);
                    if(grade==3) tfgri(level.Game.GameReplicationInfo).AddTeamRes((rate*5)*factor, myteam, false);

                    gfx=spawn(class'Taskforces.tfGeneratorFX');
                    gfx.mSpawnVecA=a.Location;
                    spawn(class'Taskforces.tfGenFXSparks',,,a.location,rotator(normal(location-a.Location)));
                    a.PlaySound(sound'TFMedia.TFConsume',SLOT_None,0.5,,,0.9+frand()*0.2);
                }
            }
        }
    nearOutpost=0;
    }
}

function Destructed(pawn killer, bool recycled)
{
	if(grade==3 && !recycled)
	{
		spawn(class'Taskforces.tfGenOverBoom');
		HurtRadius(1000, 1000, class'Taskforces.DamTypeGenFlash', 10000, Location);
        PlaySound(sound'TFMedia.tfGenOverBoom',SLOT_None,5);
	}

    super.Destructed(killer, recycled);
}

defaultproperties
{
     MaxHealth=750.000000
     BuildTime=60.000000
     chunkcount=8
     BuildingName="Generator"
     NameIndex=5
     teamflareDS=1.400000
     StaticMesh=StaticMesh'TFMedia.Buildings.tfGenerator'
     AmbientSound=Sound'TFMedia.Buildings.tfGeneratorAmb'
     DrawScale=1.250000
}
